package com.husd.framework.ddl;

import com.husd.framework.code.DDLColumn;
import com.husd.framework.code.DDLIndex;
import com.husd.framework.ddl_new.PartitionOptions;
import com.husd.framework.ddl_new.TableOption;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

public class DDL {

    /**
     * 表的英文名字
     */
    private String tableName;
    private boolean temporary = false;
    private boolean ifNotExist = false;

    /**
     * 表的中文名字
     */
    private String tableComment;
    /**
     * 表的列
     */
    private List<DDLColumn> columnList;
    /**
     * 索引信息
     */
    private List<DDLIndex> indexList;

    private TableOption tableOption;

    private PartitionOptions partitionOptions;

    public PartitionOptions getPartitionOptions() {
        return partitionOptions;
    }

    public void setPartitionOptions(PartitionOptions partitionOptions) {
        this.partitionOptions = partitionOptions;
    }

    public TableOption getTableOption() {
        return tableOption;
    }

    public void setTableOption(TableOption tableOption) {
        this.tableOption = tableOption;
    }

    public List<DDLIndex> getIndexList() {
        return indexList;
    }

    public void setIndexList(List<DDLIndex> indexList) {
        this.indexList = indexList;
    }

    public boolean isTemporary() {
        return temporary;
    }

    public void setTemporary(boolean temporary) {
        this.temporary = temporary;
    }

    public boolean isIfNotExist() {
        return ifNotExist;
    }

    public void setIfNotExist(boolean ifNotExist) {
        this.ifNotExist = ifNotExist;
    }

    public String getTableComment() {
        return tableComment;
    }

    public void setTableComment(String tableComment) {
        this.tableComment = tableComment;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {

        if (StringUtils.isNotBlank(this.tableName)) {
            throw new RuntimeException("table name已经设置过了 current:" + this.tableName + " new:" + tableName);
        }
        this.tableName = tableName;
    }

    public List<DDLColumn> getColumnList() {
        return columnList;
    }

    public void setColumnList(List<DDLColumn> columnList) {
        this.columnList = columnList;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("DDL{");
        sb.append("tableName='").append(tableName).append('\'');
        sb.append(", tableComment='").append(tableComment).append('\'');
        sb.append(", columnList=").append(columnList);
        sb.append('}');
        return sb.toString();
    }
}
